import { clone } from '@/utils/clone'

export const defaultSchema = {
    properties: [],
    ui: {
        labelWidth: '100px',
        labelPosition: 'right',
        showMessage: true,
        size: 'small'
    },
    row: {
        type: 'flex',
        style: {
            flexWrap: 'wrap'
        },
        gutter: 20
    },
    col: {
    }
}

export const rulesTypeGroup = [
    { value: 'string', label: '字符串' },
    { value: 'number', label: '数字' },
    { value: 'boolean', label: '布尔值' },
    { value: 'integer', label: '整数' },
    { value: 'float', label: '浮点数' },
    { value: 'array', label: '数组' },
    { value: 'object', label: '对象' },
    { value: 'date', label: '时间对象' },
    { value: 'url', label: 'URL地址' },
    { value: 'email', label: '邮箱' }
]

const rules = [
    // 必填
    {
        _type: 'required',
        _name: '必填',
        _checked: false,
        required: true,
        message: '必填项',
        trigger: ['change']
    },
    // 类型
    {
        _type: 'type',
        _name: '类型',
        _checked: false,
        type: 'string',
        message: '类型错误',
        trigger: ['change']
    },
    // 正则
    {
        _type: 'pattern',
        _name: '正则',
        _checked: false,
        pattern: null,
        message: '不匹配当前正则',
        trigger: ['change']
    }
    // 枚举
    // {
    //     _type: 'enum',
    //     _name: '枚举',
    //     _checked: false,
    //     enum: [],
    //     message: '不匹配当前正则'
    // }
]
/**
 * 基础表单
 * widgets
 */
export const baseDragSource = [
    {
        widget: 'radio',
        label: '单选框',
        icon: 'danxuankuangxuanzhong',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'label',
                valueKey: 'value',
                childrenKey: 'children'
            },
            enum: [
                { label: '1', value: '选项1' },
                { label: '2', value: '选项2' },
                { label: '3', value: '选项3' }
            ],
            ui: {
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'checkbox',
        label: '复选框',
        icon: 'fuxuankuang',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'label',
                valueKey: 'value',
                childrenKey: 'children'
            },
            enum: [
                { label: '1', value: '选项1' },
                { label: '2', value: '选项2' },
                { label: '3', value: '选项3' }
            ],
            ui: {
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'input',
        label: '文本框',
        icon: 'm-shurukuang',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'label',
                valueKey: 'value',
                childrenKey: 'children'
            },
            ui: {
                placeholder: '请输入',
                type: 'text',
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'autocomplete',
        label: '输入建议框',
        icon: 'm-shurukuang',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'label',
                valueKey: 'value',
                childrenKey: 'children'
            },
            enum: [
                { value: '建议1' },
                { value: '建议2' },
                { value: '建议3' }
            ],
            ui: {
                placeholder: '请输入',
                valueKey: 'value',
                debounce: 300,
                triggerOnFocus: true,
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'inputNumber',
        label: '数字框',
        icon: 'shuzishurukuang',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'label',
                valueKey: 'value',
                childrenKey: 'children'
            },
            ui: {
                placeholder: '请输入数字',
                controls: true,
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'select',
        label: '下拉框',
        icon: 'm-xialakuang',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'value',
                valueKey: 'label',
                childrenKey: 'children'
            },
            enum: [
                { label: '选项1', value: '1' },
                { label: '选项2', value: '2' },
                { label: '选项3', value: '3' }
            ],
            ui: {
                placeholder: '请选择',
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'cascader',
        label: '级联选择器',
        icon: 'jilianxuanzeqi',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'value',
                valueKey: 'label',
                childrenKey: 'children'
            },
            enum: [
                {
                    label: '选项1',
                    value: '1',
                    children: [
                        {
                            label: '选项1-1',
                            value: '1-1',
                            children: [
                                { label: '选项1-1-1', value: '1-1-1' },
                                { label: '选项1-1-2', value: '1-1-2' }
                            ]
                        }, {
                            label: '选项1-2',
                            value: '1-2'
                        }
                    ]
                },
                { label: '选项2', value: '2' },
                { label: '选项3', value: '3' }
            ],
            ui: {
                placeholder: '请选择',
                props: {
                    expandTrigger: 'click',
                    checkStrictly: false
                },
                showAllLevels: true,
                separator: '/',
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'cascaderPanel',
        label: '级联选面板',
        icon: 'jiliandongxuanzeqi',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'value',
                valueKey: 'label',
                childrenKey: 'children'
            },
            enum: [
                {
                    label: '选项1',
                    value: '1',
                    children: [
                        {
                            label: '选项1-1',
                            value: '1-1',
                            children: [
                                { label: '选项1-1-1', value: '1-1-1' },
                                { label: '选项1-1-2', value: '1-1-2' }
                            ]
                        }, {
                            label: '选项1-2',
                            value: '1-2'
                        }
                    ]
                },
                { label: '选项2', value: '2' },
                { label: '选项3', value: '3' }
            ],
            ui: {
                props: {},
                style: {
                    width: '100%'
                }
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'switch',
        label: '开关',
        icon: 'gongyezujian-kaiguan',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'label',
                valueKey: 'value',
                childrenKey: 'children'
            },
            ui: {
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'slider',
        label: '滑块',
        icon: 'icon_huakuai',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'label',
                valueKey: 'value',
                childrenKey: 'children'
            },
            ui: {
                showInputControls: true,
                showTooltip: true,
                label: '屏幕阅读标签',
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'timeSelect',
        label: '固定时间',
        icon: 'shijian',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'label',
                valueKey: 'value',
                childrenKey: 'children'
            },
            ui: {
                placeholder: '请选择时间',
                editable: true,
                pickerOptions: {
                    start: '00:00',
                    end: '23:59',
                    step: '01:00'
                },
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'timePicker',
        label: '任意时间',
        icon: 'shijian-xianxing',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'label',
                valueKey: 'value',
                childrenKey: 'children'
            },
            ui: {
                placeholder: '请选择时间',
                startPlaceholder: '开始时间',
                endPlaceholder: '结束时间',
                editable: true,
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'datePicker',
        label: '日期选择器',
        icon: '759bianjiqi_riqi',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'label',
                valueKey: 'value',
                childrenKey: 'children'
            },
            ui: {
                type: 'date',
                editable: true,
                placeholder: '请选择日期',
                startPlaceholder: '开始日期',
                endPlaceholder: '结束日期',
                format: 'yyyy-MM-dd',
                pickerOptions: {
                    firstDayOfWeek: 7
                },
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'rate',
        label: '评分',
        icon: 'pingfen',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'label',
                valueKey: 'value',
                childrenKey: 'children'
            },
            ui: {
                lowThreshold: 2,
                highThreshold: 4,
                colors: ['#C0C4CC', '#F7BA2A', '#67C23A'],
                texts: ['极差', '失望', '一般', '满意', '惊喜'],
                textColor: '#1F2D3D',
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'colorPicker',
        label: '颜色选择器',
        icon: 'yanse',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'label',
                valueKey: 'value',
                childrenKey: 'children'
            },
            enum: ['#409EFF', '#67C23A', '#E6A23C', '#F56C6C', '#909399', '#303133', '#606266', '#C0C4CC', '#DCDFE6', '#E4E7ED', '#EBEEF5', '#F2F6FC', '#000000', '#FFFFFF'],
            ui: {
                colorFormat: 'hex',
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'transfer',
        label: '穿梭框',
        icon: 'm-chuansuokuang',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'key',
                valueKey: 'label',
                childrenKey: 'children'
            },
            enum: [
                { key: '1', label: '选项1' },
                { key: '2', label: '选项2' },
                { key: '3', label: '选项3' }
            ],
            ui: {
                titles: ['列表 1', '列表 2'],
                buttonTexts: [null, null],
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'upload',
        label: '上传',
        icon: 'yunshangchuan_o',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'label',
                valueKey: 'value',
                childrenKey: 'children'
            },
            ui: {
                action: 'https://jsonplaceholder.typicode.com/posts/',
                accept: '.jpg,.png,.doc',
                name: 'file',
                showFileList: true,
                listType: 'text',
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    },
    {
        widget: 'tree',
        label: '树',
        icon: 'shuliebiao',
        property: {
            source: {
                use: false,
                http: null,
                resPath: 'data',
                labelKey: 'id',
                valueKey: 'label',
                childrenKey: 'children'
            },
            enum: [
                {
                    label: '组1',
                    id: '1',
                    children: [
                        {
                            label: '组1-1',
                            id: '1-1',
                            disabled: true
                        }, {
                            label: '组1-2',
                            id: '1-2',
                            children: [
                                { label: '组1-2-1', id: '1-2-1' }
                            ]
                        }, {
                            label: '组1-3',
                            id: '1-3',
                            children: [
                                { label: '组1-3-1', id: '1-3-1' },
                                { label: '组1-3-2', id: '1-3-2' },
                                { label: '组1-3-3', id: '1-3-3' }
                            ]
                        }
                    ]
                }, {
                    label: '组2',
                    id: '2',
                    children: [
                        {
                            label: '组2-1',
                            id: '2-1'
                        }, {
                            label: '组2-2',
                            id: '2-2'
                        }
                    ]
                }, {
                    label: '组3',
                    id: '3'
                }
            ],
            ui: {
                nodeKey: 'id',
                showCheckbox: true,
                expandOnClickNode: true,
                indent: 16,
                style: {}
            },
            col: {
                span: 24
            },
            custom: {},
            rules: clone(rules)
        }
    }
]
